﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Process : IAccessible<P_Process, Process>, ILogicEntity<P_Process, Process>
    {
        public int ID { get; set; }
        public int ProcessDefID { get; set; }
        public string ProcessName { get; set; }
        public int SignType { get; set; }
        public string SignUsers { get; set; }
        public int ChangeState { get; set; }
        public ItemStatus Status { get; set; }
        public User user { get; set; }

        public Process LoadUser(U_User u_user)
        {
            this.user = new User().Set(u_user);
            return this;
        }

        protected override void Covariant(P_Process model)
        {
            if (model != null)
            {
                this.ChangeState = model.ChangeState;
                this.ID = model.ID;
                this.ProcessDefID = model.ProcessDefID;
                this.ProcessName = model.ProcessName;
                this.SignType = model.SignType;
                this.SignUsers = model.SignUsers;
                this.Status = (ItemStatus)model.Status;
            }
        }

        protected override P_Process Inverter(Process model)
        {
            if (model != null)
            {
                return new P_Process()
                {
                    ChangeState = model.ChangeState,
                    ID = model.ID,
                    ProcessDefID = model.ProcessDefID,
                    ProcessName = model.ProcessName,
                    SignType = model.SignType,
                    SignUsers = model.SignUsers,
                    Status = (int)model.Status
                };
            }
            return null;
        }

        public Process Set(P_Process dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
